﻿package view.effect
{
    import __AS3__.vec.*;
    import com.greensock.*;
    import com.greensock.easing.*;
    import com.sh.game.util.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;

    public class BezierStar extends Sprite
    {
        private var stars:Array;
        private var tweens:Vector.<TweenMax>;
        private var bmd:BitmapData;
        private var colorTransform:ColorTransform;
        private var colorTransform2:ColorTransform;
        public static const starCls:Class = BezierStar_starCls;

        public function BezierStar()
        {
            var _loc_2:Bitmap = null;
            var _loc_3:Number = NaN;
            var _loc_4:Number = NaN;
            this.stars = new Array();
            this.tweens = new Vector.<TweenMax>;
            this.colorTransform = new ColorTransform(1, 0.8, 0.8);
            this.colorTransform2 = new ColorTransform(1, 0.7, 0.9);
            this.bmd = (new starCls() as Bitmap).bitmapData;
            var _loc_1:int = 100;
            while (_loc_1 >= 0)
            {
                
                _loc_2 = new Bitmap(this.bmd);
                _loc_3 = Math.random();
                _loc_4 = 1;
                if (_loc_3 > 0.3)
                {
                    _loc_4 = Math.random() * 0.6;
                }
                else
                {
                    _loc_4 = Math.random() * 0.3;
                }
                _loc_2.scaleY = _loc_4;
                _loc_2.scaleX = _loc_4;
                _loc_2.blendMode = BlendMode.ADD;
                if (_loc_3 > 0.7)
                {
                    _loc_2.transform.colorTransform = this.colorTransform;
                }
                else if (_loc_3 > 0.35)
                {
                    _loc_2.transform.colorTransform = this.colorTransform2;
                }
                this.stars.push(_loc_2);
                _loc_1 = _loc_1 - 1;
            }
            return;
        }// end function

        protected function addTostage(event:Event) : void
        {
            this.stage.addEventListener(KeyboardEvent.KEY_UP, this.keyDown);
            return;
        }// end function

        protected function keyDown(event:KeyboardEvent) : void
        {
            var _loc_2:* = UIGlobel.pointsDic["bag"];
            this.allMove(0, 0, _loc_2.x - 63, _loc_2.y - 62);
            return;
        }// end function

        public function allMove(param1:int, param2:int, param3:int, param4:int) : void
        {
            var _loc_7:Bitmap = null;
            var _loc_5:int = 0;
            var _loc_6:* = param1 < param3;
            while (_loc_5 <= (this.stars.length - 1))
            {
                
                _loc_7 = this.stars[_loc_5];
                _loc_7.x = param1;
                _loc_7.y = param2;
                if (!_loc_7.parent)
                {
                    this.addChild(_loc_7);
                }
                _loc_7.visible = false;
                if (this.tweens.hasOwnProperty(_loc_5))
                {
                    this.tweens[_loc_5].kill();
                }
                this.tweens[_loc_5] = TweenMax.to(_loc_7, 0.8, {delay:Math.random() * 0.4, bezier:[{x:_loc_6 ? (Math.random() * 30 + param3) : (Math.random() * 30 + 100 + param1), y:Math.random() * 50 + param2}, {x:_loc_6 ? (Math.random() * 30 + 100 + param2) : (Math.random() * 30 + param3), y:Math.random() * 50 + param4 - 100}, {x:param3 + 50, y:param4 + 50}], orientToBezier:false, ease:Linear.easeNone, onComplete:this.flyEnd, onCompleteParams:[_loc_7], onStart:this.onStart, onStartParams:[_loc_7]});
                _loc_5++;
            }
            return;
        }// end function

        public function allMoveline(param1:int, param2:int, param3:int, param4:int) : void
        {
            var _loc_7:Bitmap = null;
            var _loc_5:int = 0;
            var _loc_6:* = param1 < param3;
            while (_loc_5 <= 20)
            {
                
                _loc_7 = this.stars[_loc_5];
                _loc_7.x = param1;
                _loc_7.y = param2;
                if (!_loc_7.parent)
                {
                    this.addChild(_loc_7);
                }
                _loc_7.visible = false;
                if (this.tweens.hasOwnProperty(_loc_5))
                {
                    this.tweens[_loc_5].kill();
                }
                this.tweens[_loc_5] = TweenMax.to(_loc_7, 0.8, {delay:Math.random() * 0.4, x:param3 + 50, y:param4 + 50, ease:Linear.easeNone, onComplete:this.flyEnd, onCompleteParams:[_loc_7], onStart:this.onStart, onStartParams:[_loc_7]});
                _loc_5++;
            }
            return;
        }// end function

        public function onStart(param1:Bitmap) : void
        {
            param1.visible = true;
            return;
        }// end function

        public function flyEnd(param1:Bitmap) : void
        {
            if (param1.parent)
            {
                param1.parent.removeChild(param1);
            }
            return;
        }// end function

    }
}
